<%@ Page language="c#" Inherits="LocalBoard.Web.AddPoll" CodeFile="AddPoll.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
<html>
  <head>
    <title>AddPoll</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body onload="init();">
	
    <form id="Form1" method="post" runat="server">
<script>
function ltrim ( s )
{
	return s.replace( /^\s*/, "" );
}
function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}
function trim ( s )
{
	return rtrim(ltrim(s));
}
var itemSize = 4;
var isNew = true;
function init()
{
	if (opener.IsPollAttached())
	{
		isNew = false;
		var attachpolls = opener.GetPoll();
		if (attachpolls.substr(attachpolls.length-1, 1) == "|")
		{
			attachpolls = attachpolls.substr(0, attachpolls.length-1);
		}
		arrPollItem = attachpolls.split("|");
		for (var i=0; i<arrPollItem.length; i++)
		{
			if (i > 3)
				addItem();
			eval("document.all.item" + parseInt(i+1) + ".value = arrPollItem[i]");
		}
	}
}
function addItem()
{
    if (itemSize >= 10)
    {
        alert("Maximum poll item number is 10");
        return;
    }
    itemSize++;
    window.resizeBy(0, 29);
    document.all.DIVitem.innerHTML = document.all.DIVitem.innerHTML + 
        "<table border=0 cellpadding=0 cellspacing=0><tr><td style=padding-left:15 class=vs>" + itemSize + "." +
        "<img width=7 height=1><input type=\"text\" name=\"item" + itemSize + "\" style=\"width:239px\" class=\"box\" onclick=\"checkPrevItem(" + itemSize + ")\"></td></tr>\n" +
        "<tr><td height=9></td></tr></table>\n";
}
function checkPrevItem(index)
{
    for (var i=1; i<index; i++)
    {
        if (eval("trim(document.all.item"+i+".value)") == "")
        {
            alert("Fill in the previous item first please");
            eval("document.all.item"+i+".focus()");
            return;
        }
    }
}
function attachPoll()
{
    var sep = "|";
    var attachpolls = "";
    for (var i=1; i<=itemSize; i++)
    {
        itemvalue = eval("document.all.item"+i+".value");
        if (trim(itemvalue) == "")
            continue;
        if(i > 1) attachpolls = attachpolls + sep;
        attachpolls = attachpolls + itemvalue;
    }
	if (attachpolls != "")
	{
		opener.addPoll(attachpolls)
		if (isNew) opener.addList('', 'poll@nhn');
	}
    self.close();
}
</script>
</head>
<body topmargin="0" leftmargin="0" bgcolor="#FFFFFF">
<table width=330 cellpadding=0 cellspacing=0>
  <tr>
    <td height=30 bgcolor=8F8F8F style=padding-top:1 class=b colspan=3>
      <img src="http://cafeimgs.naver.com/img/ico_w.gif" width="3" height="5" style='margin:0 6 2 10'><span style=color:FFFFFF>Poll items</span>
    </td>
  </tr>
  <tr><td height=9 colspan=3></td></tr>
  <tr>
    <td width=4></td>
    <td width=322>
        <table width=100% cellpadding=0 cellspacing=0>
        <tr><td height=5 colspan=2></td></tr>
        <tr><td style=padding-left:15 colspan=2 class=vs>1.<img width=7 height=1><input type="text" name="item1" style="width:239px" class="box"></td></tr>
        <tr><td height=9 colspan=2></td></tr>
        <tr><td style=padding-left:15 colspan=2 class=vs>2.<img width=7 height=1><input type="text" name="item2" style="width:239px" class="box" onclick="checkPrevItem(2)"></td></tr>
        <tr><td height=9 colspan=2></td></tr>
        <tr><td style=padding-left:15 colspan=2 class=vs>3.<img width=7 height=1><input type="text" name="item3" style="width:239px" class="box" onclick="checkPrevItem(3)"></td></tr>
        <tr><td height=9 colspan=2></td></tr>
        <tr><td style=padding-left:15 colspan=2 class=vs>4.<img width=7 height=1><input type="text" name="item4" style="width:239px" class="box" onclick="checkPrevItem(4)"></td></tr>
        <tr><td height=9 colspan=2></td></tr>
        <tr><td colspan=2><div id="DIVitem"></div></td></tr>
        <tr><td colspan=2><img width=32 height=1><a onmouseover="this.style.cursor='hand'" onmouseout="this.style.cursor='default'" onclick="addItem()">[Add more item]</a></td></tr>
        <tr><td height=13 colspan=2></td></tr>
        </table>
    </td>
    <td width=4></td>
  </tr>
  <tr><td height=1 bgcolor=E3E3E3 colspan=3></td></tr>
  <tr><td height=5 colspan=3></td></tr>
  <tr><td align=center colspan=3><a href="javascript:attachPoll();" id="href1">OK</a></td></tr>
  <tr><td height=10 colspan=3></td></tr>
</table>
     </form>
<script language="javascript">
</script>
</body>
</html>
